package com.ruoyi.business.utils;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.ruoyi.common.constant.Constants;
import lombok.Data;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author liutao
 * @version 1.0
 * @description: TODO
 * @date 2024/4/11 17:38
 */
public class Demo {
    public static void main(String[] args) {
        List<ProductAttributeNameDTO> l1 = Arrays.asList(
                new ProductAttributeNameDTO(1L, "颜色"),
                new ProductAttributeNameDTO(2L, "尺码"),
                new ProductAttributeNameDTO(3L, "重量"),
                new ProductAttributeNameDTO(4L, "重量1")
        );
        List<ProductAttributeNameDTO> l2 = Arrays.asList(
                new ProductAttributeNameDTO(1L, "颜色"),
                new ProductAttributeNameDTO(2L, "重量"),
                new ProductAttributeNameDTO(3L, "材质")
        );

        List<ProductAttributeNameDTO> resultList = Stream.concat(l1.stream(), l2.stream())
                .collect(Collectors.groupingBy(ProductAttributeNameDTO::getId, Collectors.counting()))
                .entrySet().stream()
                .filter(e -> e.getValue() == 1)
                .map(e -> e.getKey())
                .map(id -> Stream.concat(l1.stream(), l2.stream()).filter(p -> p.getId().equals(id)).findFirst().get())
                .collect(Collectors.toList());
        System.out.println(resultList);
    }
}

@Data
class ProductAttributeNameDTO {
    private Long id;
    private String name;

    public ProductAttributeNameDTO(Long id, String name) {
        this.id = id;
        this.name = name;
    }
}
